"""
__author__ = '霍格沃兹测试开发学社'
__desc__ = '更多测试开发技术探讨，请访问：https://ceshiren.com/t/topic/15860'
"""
from selenium.webdriver.common.by import By

from contacts_deparment_po.page_object.base_page import BasePage
from contacts_deparment_po.utils.log_utils import logger


class ContactPage(BasePage):
    # __TEXT_TIPS = (By.ID, "js_tips")
    __MEMBER_TABLE = (By.CSS_SELECTOR, ".member_colRight_memberTable")
    # __DEPT_TABLE = (By.XPATH, '//a[text()="研发测试部"]/..//ul')
    __DEPT_TABLE = (By.XPATH, '//a[text()="研发测试部"]/..//ul//li//a')
    __TABLE_COUNT = (By.CSS_SELECTOR, "#member_list > tr")

    def get_member_infos(self):

        # WebDriverWait(self.driver, 10, 2).until(expected_conditions.visibility_of_element_located(loc_tips))
        self.wait_visible(self.__MEMBER_TABLE)
        # tips_value = self.do_find(self.__TEXT_TIPS).text
        # return tips_value
        # 方法一
        # member_table = self.do_find(self.__MEMBER_TABLE)
        # tmp_res = member_table.text
        # print(tmp_res)
        # logger.info(member_table.text)

        # 方法二
        cre_table= self.do_find(self.__MEMBER_TABLE)
        cre_table_text = cre_table.text

        mem_count = (By.CSS_SELECTOR, ".js_member_count")
        mem_count_text = self.driver.find_element(*mem_count).text
        mem_counts = mem_count_text.strip("()").rsplit("人")[0]

        table_counts = len(self.do_finds(self.__TABLE_COUNT))

        if int(mem_counts) > 20:
            while table_counts == 20:
                self.driver.find_elements(By.CSS_SELECTOR, "a.ww_pageNav_info_arrowWrap.js_next_page > span")[0].click()
                # 获取下一页table信息
                self.wait_visible(self.__MEMBER_TABLE)
                cre_table_next = self.do_find(self.__MEMBER_TABLE)
                cre_table_next_text = cre_table_next.text
                cre_table_text += cre_table_next_text
                # print(cre_table_text)
                # 获取下一页tr信息
                table_counts = len(self.do_finds(self.__TABLE_COUNT))
        return cre_table_text

    def get_dept_infos(self):

        # WebDriverWait(self.driver, 10, 2).until(expected_conditions.visibility_of_element_located(loc_tips))
        self.wait_visible(self.__DEPT_TABLE)
        # 方法一
        # tips_value = self.do_find(self.__TEXT_TIPS).text
        # return tips_value
        # 方法二
        dept_tables = self.do_finds(self.__DEPT_TABLE)
        for dept_table in dept_tables:
            dept_table_text = dept_table.text
        return dept_table_text